﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using Entities;

namespace InsuranceVehicle.AdminSite
{
    public partial class ChangePass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            EmployeeInfo emp = new EmployeeInfo();
            emp = (EmployeeInfo)Session["Employee"];
            if (emp != null)
            {
                if (emp.Department == 1)
                {
                    Menu1.ShowElement = "all";
                }
                else
                {
                    Menu1.ShowElement = "no";
                }
            }
            else
            {
                Response.Redirect("LoginAdmin.aspx");
            }
        }

        protected void btnChangePass_Click(object sender, EventArgs e)
        {
            EmployeeDataAccess db = new EmployeeDataAccess();
            EmployeeInfo emp = new EmployeeInfo();
            emp = (EmployeeInfo)Session["Employee"];
            lblErrOldPass.Visible = false;
            lblSuccess.Visible = false;
            if (IsValid)
            {
                bool confirmPass = db.ConfirmPassword(emp.EmployeeID, txtOldPass.Text);
                if (confirmPass == true)
                {
                    db.UpdatePassword(emp.EmployeeID, txtNewPassword.Text);
                    //Response.Write("<script>alert('Update successfull')</script>");
                    lblSuccess.Visible = true;
                    lblSuccess.Text = "Update successful";

                }
                else
                {
                    lblErrOldPass.Visible = true;
                    lblErrOldPass.Text = "Old password is incorrect";
                }
            }
        }
    }
}